<template>
  <div>
    <button type="button" @click="addUser">添加</button>
    <table>
      <thead>
        <tr>
          <th>姓名</th>
          <th>性别</th>
          <th>年龄</th>
        </tr>
      </thead>
      <tbody v-for="item in userList" :key="item.id">
        <tr>
          <td>{{ item.name }}</td>
          <td>{{ item.sex }}</td>
          <td>{{ item.age }}</td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userList: [
        { id: 1, name: '李四', sex: '男', age: 22 },
        { id: 2, name: '王麻子', sex: '男', age: 11 },
        { id: 3, name: '老王', sex: '女', age: '33' },
        { id: 4, name: '老谭', sex: '男', age: '44' },
        { id: 5, name: '张三', sex: '男', age: '55' }
      ]
    }
  },
  // 方法集
  methods: {
    addUser() {
      this.userList.push({ id: 1, name: '德玛西亚', sex: '女', age: 66 })
    }
  }
}
</script>

<style lang="less" scoped>
table {
  border: 1px solid #ccc;
  border-collapse: collapse;
  width: 400px;
  text-align: center;
  th,
  td {
    border: 1px solid #ccc;
  }
}
</style>
